"""
用两个栈，一个存储值，一个存储最小值
注意：每出现一次当前最小值，就要存储一次（等号）
"""

class MinStack:

    def __init__(self):
        """
        initialize your data structure here.
        """
        self.stack = []
        self.min_list = []


    def push(self, x: int) -> None:
        self.stack.append(x)
        if not self.min_list or x <= self.min_list[-1]:
            self.min_list.append(x)

    def pop(self) -> None:
        if self.stack[-1] == self.min_list[-1]:
            self.min_list.pop()
        self.stack.pop()

    def top(self) -> int:
        return self.stack[-1]

    def min(self) -> int:
        return self.min_list[-1]


# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(x)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.min()

if __name__ == '__main__':
    minStack = MinStack();
    minStack.push(-2);
    minStack.push(0);
    minStack.push(-3);
    print(minStack.min());   #返回 -3.
    minStack.pop();
    print(minStack.top());   # 返回 0.
    print(minStack.min());   # 返回 -2.